<html>
<head><meta charset="utf-8"><title>Splatting APIs · project-portable-simd · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/index.html">project-portable-simd</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html">Splatting APIs</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212356379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212356379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212356379">(Oct 05 2020 at 21:02)</a>:</h4>
<p>So my thought for a splatting API was something that lets you <code>splat()</code> an integer or float and hopefully rustc can try to type-infer the vector length you meant using the awesome and disturbing powers of generic inference that are being unleashed in PRs like this one: <a href="https://github.com/rust-lang/rust/pull/76825/files">https://github.com/rust-lang/rust/pull/76825/files</a> Though I'm not sure that works as well with tuples, which I'm filing under "maybe SIMD types should just be a tagged array?"</p>
<p>I initially mentioned a splatting API from the place of formulating an objection which maybe is not the best space for design to come from honestly <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span>  but I've given it some consideration and I realized I'm way more comfortable with f32x4 + f32 because, well, APL. I'm still ready to discuss whether or not that is best! But I gotta admit that it's a little less about inherent type clashing and more about explicitness and Rust conventions vs. other conventions.</p>
<p>But I do think splats should have their own conversion. I hadn't organized my thoughts as coherently about it then but I realized that From/Into feels less appropriate for a splat API because most From/Into conversions are... simple, and not completely lossless but notionally about as much? That isn't a hard limit, but From as I see it is mostly changing the view into or container of the data, whereas a possible f32 =&gt; f32x4 =&gt; f32 =&gt; etc. conversion isn't quite so much a round trip: it's creating data and then truncating it. I'm also a little worried about such a From/Into implementation weakening type inference, but possibly unwarrantedly?</p>
<p>As usual, it's always possible there's something else I'm missing.</p>



<a name="212356688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212356688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212356688">(Oct 05 2020 at 21:05)</a>:</h4>
<p>So I'm not sure, but I have a feeling that type inference doesn't work at all with the binary core ops? Something with the RHS type being generic.  Scalars can already be splatted into vectors with Into but that doesn't work</p>



<a name="212357563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212357563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212357563">(Oct 05 2020 at 21:12)</a>:</h4>
<p>do you mean <code>fn splat&lt;V: SomeSimdTrait&lt;Item = Self&gt;&gt;(self) -&gt; V</code> on primitive ints/floats so that you could do <code>3.0f32.splat::&lt;f32x4&gt;()</code> or something?</p>
<p>seems fine, assuming in this future world exists after const traits work or whatever. in my own code (when not just using <code>_mmX_set1_foo</code>) i have a macro i like to use that allows <code>simd_const![s; 4]</code> or <code>simd_const![x, y, z, w]</code>. but i don't really love it — it's only a macro because of const fn limitations.</p>
<p>(edit: note that one downside of this macro is that i have one version of it for each primitive type — putting it as an inherent function (as you suggest, if i'm interpreting it right) avoids this, although i do think probably a <code>f32x4::splat(v: f32) -&gt; f32x4</code>-style constructor is still desirable)</p>



<a name="212358071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212358071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212358071">(Oct 05 2020 at 21:17)</a>:</h4>
<p>Something like that, yes.<br>
<span class="user-mention" data-user-id="312331">@Caleb Zulawski</span> hrm, that's true, it _is_ the case that they're type generic.</p>



<a name="212358434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212358434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212358434">(Oct 05 2020 at 21:21)</a>:</h4>
<p>But that doesn't actually mean that type inference can never work, otherwise collect() could not work. However, IntoIterator/FromIterator do exist because the type inference of rustc is generally too weak to discern correctly using <strong>From</strong> impls because there's just so many different ways to go.</p>



<a name="212358683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212358683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212358683">(Oct 05 2020 at 21:23)</a>:</h4>
<p>I mean, with collect you either use a turbo fish or concretely define the type on the left, right?</p>



<a name="212358691"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212358691" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212358691">(Oct 05 2020 at 21:23)</a>:</h4>
<p>So I think that's the same</p>



<a name="212358762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212358762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212358762">(Oct 05 2020 at 21:24)</a>:</h4>
<p>No, .collect() can successfully discern without either.</p>



<a name="212358777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212358777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212358777">(Oct 05 2020 at 21:24)</a>:</h4>
<p>this doesn't seem meaningfully more complex than <code>str::parse</code> (it seems simpler to me, but I could be mistaken), which works nicely in practice.</p>



<a name="212358824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212358824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212358824">(Oct 05 2020 at 21:24)</a>:</h4>
<p>i also think turbofish is preferrable to needing to import a trait for ergonomics, but i guess i could imagine people disagreeing with me on that</p>



<a name="212358859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212358859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212358859">(Oct 05 2020 at 21:25)</a>:</h4>
<p>yeah</p>



<a name="212359002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212359002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212359002">(Oct 05 2020 at 21:26)</a>:</h4>
<p>Well at that point you can just do a + f32x4::splat(b)</p>



<a name="212359011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212359011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212359011">(Oct 05 2020 at 21:26)</a>:</h4>
<p>Iterator::collect in fact usually succeeds on pure inference more often than str::parse, probably because it has a more bounded set to go through. (personal observation, not assertion of pure fact)</p>



<a name="212359020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212359020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212359020">(Oct 05 2020 at 21:26)</a>:</h4>
<p>No need for a generic</p>



<a name="212359309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212359309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212359309">(Oct 05 2020 at 21:29)</a>:</h4>
<p>by APL I mean this one, also: <a href="https://en.wikipedia.org/wiki/APL_(programming_language)">https://en.wikipedia.org/wiki/APL_(programming_language)</a></p>



<a name="212359608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212359608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212359608">(Oct 05 2020 at 21:32)</a>:</h4>
<p>I guess my question as far as type inference is concerned, how could we make a trait that somehow infers differently than Into?  I think fundamentally scalars splat into multiple vectors, and anyone can implement more core ops over vectors in their own crate, so that double inference (the into trait and the op rhs type) _must_ fail</p>



<a name="212359637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212359637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212359637">(Oct 05 2020 at 21:32)</a>:</h4>
<p>I think it inherently needs to be implemented on the vector type to avoid that problem</p>



<a name="212359645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212359645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212359645">(Oct 05 2020 at 21:32)</a>:</h4>
<p>maybe it could be made to work as <code>some_f32.splat::&lt;4&gt;()</code>? honestly i suspect this might be a little "too cute". i also suspect it needs terrifying amounts of system shenanigans to map 4 and f32 to f32x4 (okay, maybe it wouldn't be that bad, but it still might be too much for inference)</p>



<a name="212359687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212359687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212359687">(Oct 05 2020 at 21:33)</a>:</h4>
<p>I don't think that would work without specialization</p>



<a name="212359710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212359710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212359710">(Oct 05 2020 at 21:33)</a>:</h4>
<p>And const specialization at that (idk if that's a thing?)</p>



<a name="212359793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212359793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212359793">(Oct 05 2020 at 21:34)</a>:</h4>
<p>You could make independent traits like Splat2, Splat4, etc that are associated with particular vectors</p>



<a name="212359863"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212359863" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212359863">(Oct 05 2020 at 21:35)</a>:</h4>
<p>But that doesn't seem particularly elegant (and doesn't really work with generic widths)</p>



<a name="212360017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212360017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212360017">(Oct 05 2020 at 21:37)</a>:</h4>
<p>Well, I raised the question because I wanted to see if people were game for the idea. I think exploring the total design space and all the nuances of type inference are slightly beyond the bounds of "should we?"</p>



<a name="212360171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212360171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212360171">(Oct 05 2020 at 21:38)</a>:</h4>
<p>Well, this doesn't solve the ops issue, but I think a trait could be implemented across all vectors that implements splatting (among other common operations)</p>



<a name="212360211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212360211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212360211">(Oct 05 2020 at 21:39)</a>:</h4>
<p>Probably in a num-traits style trait</p>



<a name="212361880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212361880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212361880">(Oct 05 2020 at 21:59)</a>:</h4>
<p>yeah, i know i mentioned a simd trait, but i think there should be a good reason for doing so. i think it's easy to go overboard with a trait-heavy design, and make things confusing and hard to use. (imo the stdlib avoiding this for the primitive types, was the right call, even though it's inconvenient at times).</p>



<a name="212362179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212362179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212362179">(Oct 05 2020 at 22:02)</a>:</h4>
<p>Fundamentally, if you want all lanes multiplied by two, then you should be able to just write</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">x</span><span class="w"> </span><span class="o">*=</span><span class="w"> </span><span class="mf">2.0</span><span class="p">;</span><span class="w"></span>
</code></pre></div>

<p>and <em>anything</em> wordier than that gets the stink eye from me.</p>



<a name="212364783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212364783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212364783">(Oct 05 2020 at 22:33)</a>:</h4>
<p>From a mathematical perspective I tend to agree.  You don't need to annotate that you are extending a scalar into a vector</p>



<a name="212365752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212365752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212365752">(Oct 05 2020 at 22:46)</a>:</h4>
<p>what about having a module-level generic <code>splat</code> function? That way, adding 5 to all lanes would be:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">x</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">splat</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span><span class="w"></span>
</code></pre></div>

<p>It would be declared something like:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">SplatTarget</span>: <span class="nb">Sized</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Item</span>: <span class="nb">Sized</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">splat</span><span class="p">(</span><span class="n">item</span>: <span class="nc">Self</span>::<span class="n">Item</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">splat</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">SplatTarget</span><span class="o">&gt;</span><span class="p">(</span><span class="n">item</span>: <span class="nc">T</span>::<span class="n">Item</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">T</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">T</span>::<span class="n">splat</span><span class="p">(</span><span class="n">item</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p>declaring it that way would also let you do:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">x</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">i32x4</span>::<span class="n">splat</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span><span class="w"></span>
<span class="n">x</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="n">splat</span>::<span class="o">&lt;</span><span class="n">i32x4</span><span class="o">&gt;</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="212365978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212365978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212365978">(Oct 05 2020 at 22:49)</a>:</h4>
<p>I don't think the type inference would work in the first example.  I stated it a bit further up but I don't think any type inference will work on the right-hand side of any of the core ops since since a user could always implement it in their own crate</p>



<a name="212366117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212366117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212366117">(Oct 05 2020 at 22:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/Splatting.20APIs/near/212364783">said</a>:</p>
<blockquote>
<p>From a mathematical perspective I tend to agree.  You don't need to annotate that you are extending a scalar into a vector</p>
</blockquote>
<p>I disagree, since I expect things like adding <code>i32x4</code>and <code>i32</code> to be a type error. For me, invisibly splatting only makes sense for mul and div, but I think it's better to be a bit verbose to improve clarity as well as for consistency with ops other than mul and div.</p>



<a name="212366199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212366199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212366199">(Oct 05 2020 at 22:52)</a>:</h4>
<p>Sorry, when I said from a mathematical perspective, I meant it's normal to write something like 2 v bar to mean multiply each element by two in v bar</p>



<a name="212366233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212366233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212366233">(Oct 05 2020 at 22:53)</a>:</h4>
<p>Which also carries over to many vector-first languages like matlab or mathematica</p>



<a name="212366234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212366234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212366234">(Oct 05 2020 at 22:53)</a>:</h4>
<p>yeah, looking at <code>i32x4::splat(5)</code> vs <code>5i32.splat::&lt;i32x4&gt;()</code> vs <code>splat::&lt;i32x4&gt;(5)</code> honestly its hard for me not to think the first is clearly the best. least noisy, probably the simplest</p>



<a name="212366329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212366329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212366329">(Oct 05 2020 at 22:55)</a>:</h4>
<p>i don't really like the thought of this being on <code>trait SplatTarget</code> since it would either need to be in a/the prelude, or manually imported. which is kind of annoying unless there's an actual benefit (and i don't think there is here)</p>



<a name="212366587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212366587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212366587">(Oct 05 2020 at 22:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/Splatting.20APIs/near/212365978">said</a>:</p>
<blockquote>
<p>I don't think the type inference would work in the first example.  I stated it a bit further up but I don't think any type inference will work on the right-hand side of any of the core ops since since a user could always implement it in their own crate</p>
</blockquote>
<p>It seems to work fine:<br>
<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=48bebda6de3f069add70f544c02b9c81">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=48bebda6de3f069add70f544c02b9c81</a></p>



<a name="212366642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212366642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212366642">(Oct 05 2020 at 22:59)</a>:</h4>
<p>well if you're going to put the type name first, you'll probably just use <code>from</code> since that's one whole letter less. And even then, it's really wordy.</p>



<a name="212366823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212366823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212366823">(Oct 05 2020 at 23:01)</a>:</h4>
<p>cool.</p>



<a name="212366982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212366982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212366982">(Oct 05 2020 at 23:03)</a>:</h4>
<p>Interesting, I wonder what exactly is different about that and using Into</p>



<a name="212367215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212367215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212367215">(Oct 05 2020 at 23:05)</a>:</h4>
<p>I suppose I am starting to wonder what foot-guns we are avoiding by not supporting mixed vector-scalar ops on the first place</p>



<a name="212367258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212367258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212367258">(Oct 05 2020 at 23:05)</a>:</h4>
<p>Because in the end vectors and scalars _are_ types you want to use together</p>



<a name="212367329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212367329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212367329">(Oct 05 2020 at 23:06)</a>:</h4>
<p>Well from my perspective mixed vector + scalar ops are a slightly different question from how best to implement other type conversions / expansions / etc.</p>



<a name="212367763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212367763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212367763">(Oct 05 2020 at 23:12)</a>:</h4>
<p>If we ignore the core ops issue, I personally think it makes sense to have a trait over vectors that implements splat</p>



<a name="212367777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212367777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212367777">(Oct 05 2020 at 23:12)</a>:</h4>
<p>(which may not be a part of std::simd)</p>



<a name="212367964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212367964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212367964">(Oct 05 2020 at 23:15)</a>:</h4>
<p>wouldn't that just be <code>From</code> though? i think splatting is specific enough that it doesn't need to have its own trait... like, i don't know what kind of functions i'd write that are generic over the ability to splat a number into a vector.</p>



<a name="212368042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212368042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212368042">(Oct 05 2020 at 23:16)</a>:</h4>
<p>Yeah, might just be from</p>



<a name="212368202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212368202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212368202">(Oct 05 2020 at 23:18)</a>:</h4>
<p>Tested module-level <code>splat</code> from a different crate: <a href="https://github.com/programmerjake/simd-splat-demo">https://github.com/programmerjake/simd-splat-demo</a><br>
It still works fine.</p>



<a name="212368288"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212368288" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212368288">(Oct 05 2020 at 23:19)</a>:</h4>
<p>So my question is what are we trying to solve that isn't solved by From/Into</p>



<a name="212368434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212368434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212368434">(Oct 05 2020 at 23:20)</a>:</h4>
<p>Like I don't necessarily have a problem with a dedicated splat function and trait but that seems like a lot of extra code that does nearly the same thing with slightly different type inference properties</p>



<a name="212368448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212368448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212368448">(Oct 05 2020 at 23:20)</a>:</h4>
<p>more simply: "from/into is a splat" is not obvious.</p>



<a name="212368477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212368477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212368477">(Oct 05 2020 at 23:20)</a>:</h4>
<p>Okay, that may be a good reason</p>



<a name="212368552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212368552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212368552">(Oct 05 2020 at 23:21)</a>:</h4>
<p>Kinda like <code>str::parse</code> should be different from just <code>try_into</code></p>



<a name="212368687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212368687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212368687">(Oct 05 2020 at 23:23)</a>:</h4>
<p>the command expressed is "using this base data, programmatically generate / reify this data as an entirely different thing".<br>
in an obviously trivial way, of course, which is why it can be easily encoded.</p>



<a name="212368756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212368756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212368756">(Oct 05 2020 at 23:23)</a>:</h4>
<p>In that case I think that works with what I previously said, vectors can implement FromScalar</p>



<a name="212368814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212368814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212368814">(Oct 05 2020 at 23:24)</a>:</h4>
<p>Taking a vector and doing a scalar add... we can discuss whether or not that is acceptable w/o contending that splat should be the default from/into implementation elsewhere.</p>



<a name="212368832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212368832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212368832">(Oct 05 2020 at 23:24)</a>:</h4>
<p>i think there's an argument someone could make that From should only set the bottom lane/element/w/e. i mean, i think this is obviously wrong, but there's (arguably) precedence in vendor functions like _mm_cvtsi32_si128 (which has "convert" in the name, although nobody would ever document it that way, i think).</p>
<p>that said, if From is vague, i don't know if <code>trait Splat</code> is the solution. an <del>intrinsic</del> inherent method is fine.</p>



<a name="212368888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212368888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212368888">(Oct 05 2020 at 23:25)</a>:</h4>
<p>My only opinion is that the trait should be implemented on the vector and not on the scalar</p>



<a name="212368893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212368893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212368893">(Oct 05 2020 at 23:25)</a>:</h4>
<p>Since it's a property of the vector, not the scalar</p>



<a name="212368995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212368995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212368995">(Oct 05 2020 at 23:26)</a>:</h4>
<p>Also fine with removing the From implementation in favor of this</p>



<a name="212369014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369014">(Oct 05 2020 at 23:26)</a>:</h4>
<p>I really think we should use traits instead of magic generic intrinsics wherever it doesn't cause problems.</p>



<a name="212369051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369051">(Oct 05 2020 at 23:27)</a>:</h4>
<p>Sorry, "intrinsic method"?</p>



<a name="212369063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369063">(Oct 05 2020 at 23:27)</a>:</h4>
<p>sorry inherent</p>



<a name="212369278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369278">(Oct 05 2020 at 23:30)</a>:</h4>
<p>I basically view a default From/Into as a very strong statement... "this conversion is always valid" (explicit as it's not TryFrom) "and always unambiguous and always in the way you want" (implicit by being the default conversion trait on everything).</p>



<a name="212369287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369287">(Oct 05 2020 at 23:30)</a>:</h4>
<p>my point is basically that (IMO) one of the good things about libcore/libstd is that's generally pretty deliberate and conservative about when it introduces (public) traits. two types having a similar function isn't enough (the ecosystem can/will pick this up). this also allows things to vary in situations where it makes sense</p>



<a name="212369334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369334">(Oct 05 2020 at 23:31)</a>:</h4>
<p>One advantage of traits over inherent methods is you can write <code>splat(5i32)</code> when it's not ambiguous  instead of <code>i32x4::splat(5i32)</code> or the even worse <code>5i32.splat4()</code></p>



<a name="212369428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369428">(Oct 05 2020 at 23:32)</a>:</h4>
<p><span class="user-mention" data-user-id="281757">@Jubilee</span> I think I agree with your point, that here the definition of converting a scalar into a vector is contentious/not obvious enough for From/Into</p>



<a name="212369430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369430">(Oct 05 2020 at 23:32)</a>:</h4>
<p>yeah, and the stdlib can use a trait like that without exposing it. i just don't know if splatting is where we want to spend API complexity budget</p>



<a name="212369477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369477">(Oct 05 2020 at 23:33)</a>:</h4>
<p>( with the few cases where it's not <em>completely</em> unambiguous and makes a choice as to how you're going to get it being literally things hotly debated for years. )</p>



<a name="212369480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369480">(Oct 05 2020 at 23:33)</a>:</h4>
<p>I also tend to agree that the ecosystem can pick it up as long as we provide the inherent methods</p>



<a name="212369520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369520">(Oct 05 2020 at 23:34)</a>:</h4>
<p>though also having inherent methods on all vector types to avoid needing to import traits definitely could be useful</p>



<a name="212369556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369556">(Oct 05 2020 at 23:34)</a>:</h4>
<p>Also many algorithms are _not_ generic and the inherent method is probably better in those cases</p>



<a name="212369667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369667">(Oct 05 2020 at 23:36)</a>:</h4>
<p>I would argue for using the generic module-level function whenever not ambiguous since it's shorter to type</p>



<a name="212369700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369700">(Oct 05 2020 at 23:36)</a>:</h4>
<p>It's shorter but it's significantly less obvious what you're splatting to</p>



<a name="212369989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212369989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212369989">(Oct 05 2020 at 23:42)</a>:</h4>
<p>yeah, and i also suspect you definitely have the vector type/s you're working with imported already</p>



<a name="212370037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212370037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212370037">(Oct 05 2020 at 23:43)</a>:</h4>
<p>if it's not sufficiently obvious, that means it's ambiguous even if the compiler doesn't complain, therefore those cases should use the inherent method. I would guess that in the vast majority of cases it <em>is</em> sufficiently obvious. e.g.:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">average_color</span><span class="p">(</span><span class="n">pixels</span>: <span class="kp">&amp;</span><span class="p">[</span><span class="n">f32x4</span><span class="p">])</span><span class="w"> </span>-&gt; <span class="nc">f32x4</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">sum</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">f32x4</span>::<span class="n">splat</span><span class="p">(</span><span class="mf">0.0</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="k">for</span><span class="w"> </span><span class="n">pixel</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">pixels</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">sum</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="o">*</span><span class="n">pixel</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="n">sum</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">splat</span><span class="p">(</span><span class="n">pixels</span><span class="p">.</span><span class="n">len</span><span class="p">()</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">f32</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="212370535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212370535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212370535">(Oct 05 2020 at 23:51)</a>:</h4>
<p>not to distract from your point but i'd probably argue that we should <code>impl ops::Div&lt;f32, Output = f32x4&gt; for f32x4</code> (and mul) rather than require explicit splatting for e.g. the final div</p>



<a name="212370703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212370703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212370703">(Oct 05 2020 at 23:54)</a>:</h4>
<p>i dont feel that strongly about it, but i suspect you'll see people splatting all their constants up front if you require the explicit splat, (as a manual LICM or the like, when really this doesn't matter). i've definitely seen this in the past, where people overestimate the cost of creating vectors.</p>



<a name="212370724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212370724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212370724">(Oct 05 2020 at 23:55)</a>:</h4>
<p>(that said i really don't care <em>that</em> much here, and perhaps its more in line with rust style to keep things explicit)</p>



<a name="212372220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212372220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212372220">(Oct 06 2020 at 00:20)</a>:</h4>
<p>MMm, I think we will get a better feel of what different APIs actually look like once we gain more experience with them.</p>



<a name="212372239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Splatting%20APIs/near/212372239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Splatting.20APIs.html#212372239">(Oct 06 2020 at 00:21)</a>:</h4>
<p>and have more feedback from people who don't always SIMD.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>